package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.UsersService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.Users;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.UsersQuery;

/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/users")
@RestController
public class UsersController extends BaseController {
	@Resource
	private UsersService usersService;

	@RequestMapping("/list")
	public ResponseVo getDataList(UsersQuery query){
		return getSuccessResponseVo(this.usersService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody Users bean){
		this.usersService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody Users bean){
		this.usersService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<Users> list){
		this.usersService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<Users> list){
		this.usersService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据UserID查询
	 */
	@GetMapping("/userID")
	public ResponseVo getByUserID(Integer userID){
		return getSuccessResponseVo(this.usersService.getByUserID(userID));
	}

	/**
	 * 根据UserID更新
	 */
	@PutMapping("/userID")
	public ResponseVo updateByUserID(@Valid Users bean, Integer userID){
		this.usersService.updateByUserID(bean,userID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据UserID删除
	 */
	@DeleteMapping("/userID")
	public ResponseVo deleteByUserID(Integer userID){
		this.usersService.deleteByUserID(userID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据Username查询
	 */
	@GetMapping("/username")
	public ResponseVo getByUsername(String username){
		return getSuccessResponseVo(this.usersService.getByUsername(username));
	}

	/**
	 * 根据Username更新
	 */
	@PutMapping("/username")
	public ResponseVo updateByUsername(@Valid Users bean, String username){
		this.usersService.updateByUsername(bean,username);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据Username删除
	 */
	@DeleteMapping("/username")
	public ResponseVo deleteByUsername(String username){
		this.usersService.deleteByUsername(username);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据Email查询
	 */
	@GetMapping("/email")
	public ResponseVo getByEmail(String email){
		return getSuccessResponseVo(this.usersService.getByEmail(email));
	}

	/**
	 * 根据Email更新
	 */
	@PutMapping("/email")
	public ResponseVo updateByEmail(@Valid Users bean, String email){
		this.usersService.updateByEmail(bean,email);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据Email删除
	 */
	@DeleteMapping("/email")
	public ResponseVo deleteByEmail(String email){
		this.usersService.deleteByEmail(email);
		return getSuccessResponseVo(null);
	}

}